package com.devops.admin.util;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * @ClassNem ThreadPoolSingleton
 * @Description TODO
 * @Author heyabo
 * @Date 2022/4/1 16:33
 * @Version 1.0
 **/
@Slf4j
public class ThreadPoolSingleton {
    private final ExecutorService executorService;

    private ThreadPoolSingleton() {

        executorService = new ThreadPoolExecutor(2, Integer.MAX_VALUE,
                0L, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>());
    }


    private static ThreadPoolSingleton instance;

    public static ThreadPoolSingleton getInstance() {
        if (instance == null) {
            instance = new ThreadPoolSingleton();
        }
        return instance;
    }

    public void executeTask(Runnable runnable) {
        executorService.execute(runnable);
    }

}
